home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / demos / OpenGL / space / input.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  52KB  |  1,566 lines

  1. /*
  2.  * Copyright (C) 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <sys/types.h>
  18. #include <sys/ipc.h>
  19. #include <sys/shm.h>
  20. #ifdef SOUND
  21. #include <audio.h>
  22. #endif
  23. #include "space.h"
  24.  
  25. static Matrix idmatrix = {
  26.       1.0, 0.0, 0.0, 0.0,
  27.       0.0, 1.0, 0.0, 0.0,
  28.       0.0, 0.0, 1.0, 0.0,
  29.       0.0, 0.0, 0.0, 1.0
  30. };
  31.  
  32. static Matrix hermite = {
  33.       2.0, -3.0, 0.0, 1.0,
  34.      -2.0,  3.0, 0.0, 0.0,
  35.       1.0, -2.0, 1.0, 0.0,
  36.       1.0, -1.0, 0.0, 0.0
  37. };
  38.  
  39. extern V4        raww[NUM_CLIP_PLANES] ;
  40. extern t_galaga  ggaa[STARSQ][STARSQ] ;
  41. extern sint32    timer_flag ;   
  42.  
  43. extern char  mem_col_nme[32] ;
  44. extern char  mem_ele_nme[32] ;
  45. extern char *mem_col_ptr ;
  46. extern char *mem_ele_ptr ;
  47.  
  48. t_stopwatch      Counter ;
  49. V4               plum[NUM_CLIP_PLANES] ;
  50. static t_stars   dodo[DODO_SIZE] ;
  51. static t_stars   erikl[NUMBER_OF_STARS] ;
  52. char             StarName[NUMBER_OF_STARS][16] ;
  53. flot32           lut[4096] ;
  54. static t_const   constellation ;
  55.  
  56. #if STATS
  57. static long feed_buff[256];
  58. static sint32 statistics(long);
  59. #endif
  60.  
  61. /**********************************************************************
  62. *  initialize_time()                                                
  63. **********************************************************************/
  64. void initialize_time(void)
  65.  
  66. {
  67.    Counter.click     = 0 ;
  68.    Counter.timer_old = check_timer() ;
  69.    Counter.timer     = check_timer() ;
  70.  
  71.    reverse_julian_date(Counter.D,Counter.date) ;
  72. }
  73.  
  74. /**********************************************************************
  75. *  spQuantifyMachine()                                                
  76. **********************************************************************/
  77. void spQuantifyMachine(void)
  78. {
  79.    Counter.alpha  = 0 ;
  80.  
  81.    switch (Counter.winst.hwid)  {
  82.      case SP_HW_RE:
  83.        Counter.alpha |= HW_AAPNT ;
  84.        Counter.alpha |= HW_AALIN ;
  85.        Counter.alpha |= HW_FATPT ;
  86.        Counter.flags |= TEXTR_FLAG ;
  87.        Counter.hw_graphics =  0 ;
  88.        Counter.stars_per_square = 256 ;
  89.        Counter.cutoff = 0.05 ;
  90.        break;
  91.  
  92.      case SP_HW_VGX:
  93.        Counter.alpha |= HW_AAPNT ;
  94.        Counter.alpha |= HW_AALIN ;
  95.        Counter.alpha |= HW_FATPT ;
  96.        Counter.flags |= TEXTR_FLAG ;
  97.        Counter.hw_graphics =  0 ;
  98.        Counter.stars_per_square = 192 ;
  99.        Counter.cutoff = 0.05 ;
  100.        break;
  101.  
  102.      case SP_HW_GT:
  103.        Counter.hw_graphics = -1 ;
  104.        Counter.stars_per_square = 160 ;
  105.        Counter.cutoff = 0.05 ;
  106.        break;
  107.  
  108.      case SP_HW_LG:
  109.        Counter.alpha |= HW_SOUND ;
  110.        Counter.alpha |= HW_FATPT ;
  111.        Counter.flags |= SLOWZ_FLAG ;
  112.        Counter.hw_graphics = -2 ;
  113.        Counter.stars_per_square = 128 ;
  114.        Counter.cutoff = 0.10 ;
  115.        break;
  116.  
  117.      case SP_HW_XG:
  118.        Counter.alpha |= HW_AAPNT ;
  119.        Counter.alpha |= HW_AALIN ;
  120.        Counter.alpha |= HW_SOUND ;
  121.        Counter.alpha |= HW_FATPT ;
  122.        Counter.hw_graphics = -1 ;
  123.        Counter.stars_per_square = 160 ;
  124.        Counter.cutoff = 0.05 ;
  125.        break;
  126.  
  127.      default:
  128.      case SP_HW_PI:
  129.      case SP_HW_UNKNOWN:
  130.        Counter.hw_graphics = -2 ;
  131.        Counter.stars_per_square = 128 ;
  132.        Counter.cutoff = 0.05 ;
  133.        break;
  134.      }
  135. }
  136.  
  137. /**********************************************************************
  138. *  initialize_shmem()                                                
  139. **********************************************************************/
  140. void initialize_shmem(t_boss *flaggs)
  141.  
  142. {  char   ghw[64] ;
  143.    t_body *tb ;
  144.    sint32 i,j,m[3] ;
  145.    flot32 *d ;
  146.  
  147.    mem_col_nme[0] = '\0' ;
  148.    mem_ele_nme[0] = '\0' ;
  149.  
  150.    if ((mem_ele_ptr = (char *) malloc(MAX_ELEV_BYTES)) == NULL)  {
  151.      printf("INTERNAL ERROR: malloc failed for elevation data array\n") ;
  152.      exit(0) ;
  153.      }
  154.  
  155.    if ((mem_col_ptr = (char *) malloc(MAX_COLR_BYTES)) == NULL)  {
  156.      printf("INTERNAL ERROR: malloc failed for color data array\n") ;
  157.      exit(0) ;
  158.      }
  159.  
  160.    for (d=(flot32 *)&j,i=0; i<4096; i++)  {
  161.      j = (i<<19) ;
  162.      lut[i] = exp(-0.75*log(*d)) ;
  163.      }
  164.  
  165.    Counter.noroll = 0 ;
  166.    Counter.attach = 1 ;
  167.    Counter.timacc = 1.0 ;
  168.    Counter.S      = 20.0 ;
  169.  
  170.    spCopyMatrix((flot32 *)Counter.mat,(flot32 *)idmatrix) ;
  171.  
  172.    init_stars() ;
  173.  
  174.    Counter.constobj = init_cnstl() ;
  175.  
  176.    Counter.x = SOL_X_GRID ;
  177.    Counter.y =  0 ;
  178.    Counter.z = SOL_Z_GRID ;
  179.    Counter.infoco = STELL_COLR ;
  180.    Counter.status = STELL_STAT ;
  181.    Counter.star_current = 0 ;
  182.  
  183.    generate_star_squares() ;
  184.  
  185.    printf("Nearest star is %s\n",StarName[Counter.star_current]) ;
  186.  
  187.    create_solar_system(Counter.star_current,flaggs,&ggaa[Counter.z][Counter.x]) ;
  188.  
  189.    /* set initial starting position at space station */
  190.    Counter.eye.x = 0.0 ;
  191.    Counter.eye.y = 0.0 ;
  192.    Counter.eye.z = 0.0 ;
  193.    scan_star_system(flaggs) ;
  194.  
  195.    tb = (t_body *) flaggs->star[0].next[2] ;
  196.    Counter.eye.x = tb->posit.x ;
  197.    Counter.eye.y = tb->posit.y ;
  198.    Counter.eye.z = tb->posit.z ;
  199.    scan_star_system(flaggs) ;
  200.  
  201.    Counter.eye.x += flaggs->stat.posit.x - 500.0 ;
  202.    Counter.eye.y += flaggs->stat.posit.y ;
  203.    Counter.eye.z += flaggs->stat.posit.z ;
  204.  
  205.    Counter.locun = 0;
  206.    Counter.galobj[0] = make_galaxy_object(0) ;
  207.    Counter.galobj[1] = make_galaxy_object(1) ;
  208.  
  209.    Counter.starobj = generate_galaxy_stars() ;
  210.  
  211.    if (Counter.alpha & HW_FATPT)
  212.      glPointSize(2.0) ;
  213.  
  214.    if (Counter.alpha & HW_SOUND)  {
  215.      if ((Counter.shmid = shmget(0,32,0x3b6)) == -1)  {
  216.        printf("INTERNAL ERROR: shmget() failed\n") ;
  217.        exit() ;
  218.        }
  219.  
  220.      if ((sint32)(Counter.shmad = shmat(Counter.shmid,0,SHM_RND)) == -1) {
  221.        printf("INTERNAL ERROR: shmat() failed\n") ;
  222.        exit() ;
  223.        }
  224.      }
  225.  
  226.    if (glIsList(Counter.locun))
  227.      glDeleteLists(Counter.locun,1);
  228.  
  229.    Counter.locun = glGenLists(1);
  230.    glNewList(Counter.locun,GL_COMPILE) ;
  231.    draw_all_them_stars(0);
  232.    glEndList();
  233.  
  234.    spRingBell() ;
  235. }
  236.  
  237. /**********************************************************************
  238. *  read_time()                                                
  239. **********************************************************************/
  240. void read_time(void)
  241.  
  242. {
  243.    Counter.click++ ;
  244.    Counter.timer_old = Counter.timer ;
  245.    Counter.timer     = check_timer() ;
  246.  
  247.    if ((Counter.click & 15) == 15)
  248.      reverse_julian_date(Counter.D,Counter.date) ;
  249. }
  250.  
  251. /********************************************************************** 
  252. *  evaluate_mouse()
  253. **********************************************************************/
  254. void evaluate_mouse(t_boss *flaggs)
  255.  
  256. {  register sint32 i,lm,mm,rm;
  257.    register flot32 c1,c2,c3,s1,s2,s3,xpos,ypos,Droll,Dpitch,Dyaw;
  258.    register Matrix m ;
  259.    register V4     *c ;
  260.    static   sint32 frame_sleep = 0 ;
  261.    static   sint32 history = 0 ;
  262.             sint32 pvbuf[8] ;
  263.             flot64 vel;
  264.  
  265.    xpos = Counter.mouse_x;
  266.    ypos = Counter.mouse_y;
  267.  
  268.    lm = Counter.mouse_b & SP_LMOUSE;
  269.    mm = Counter.mouse_b & SP_MMOUSE;
  270.    rm = Counter.mouse_b & SP_RMOUSE;
  271.  
  272.    if ((lm && !mm && !rm) || (!lm && mm && !rm))  {
  273.      history++ ;
  274.      if (history > 127) history = 127 ;
  275.      }
  276.    else if (!lm && !mm && !rm)  {
  277.      history-- ;
  278.      if (history < 0) history = 0 ;
  279.      }
  280.  
  281.    frame_sleep-- ;
  282.  
  283.    if (lm && (frame_sleep < 0) && (Counter.flags & PANEL_FLAG))  {
  284.      check_menu(flaggs) ;
  285.      frame_sleep = ((Counter.fps < 3.0) ? 1 : Counter.fps/3.0) ;
  286.      }
  287.  
  288.    if (!(Counter.flags & SHIFT_FLAG))  {
  289.      if (rm && !lm && !mm)  {
  290.        Counter.noroll = !Counter.noroll ; 
  291.        sginap(5);
  292.        }
  293.  
  294.      if (lm && mm && rm)
  295.        el_cheato(flaggs,3,Counter.mat) ;
  296.      else if (lm && mm)
  297.        el_cheato(flaggs,0,Counter.mat) ;
  298.      else if (mm && rm)
  299.        el_cheato(flaggs,1,Counter.mat) ;
  300.      else if (lm && rm)
  301.        el_cheato(flaggs,2,Counter.mat) ;
  302.   
  303.      xpos = (xpos - Counter.winorigx - Counter.winsizex/2)/400.0;
  304.      ypos = (ypos - Counter.winorigy - Counter.winsizey/2)/400.0;
  305.  
  306.      Droll  = ((Counter.noroll) ? 0 : M_PI*xpos/180.0) ;
  307.      Dpitch = M_PI*ypos/180.0 ;
  308.      Dyaw   = M_PI*xpos/720.0 ;
  309.  
  310.      /* set volume */
  311. #ifdef SOUND
  312.      if ((Counter.alpha & HW_SOUND) && (Counter.flags & SOUND_FLAG))  {
  313.        c1 = 3000.0* (fabs(Dyaw) + fabs(Dpitch) + fabs(Droll)) ;
  314.        if (c1 > 127) c1 = 127.0 ;
  315.        pvbuf[0] = AL_LEFT_SPEAKER_GAIN ;
  316.        pvbuf[1] = c1 + history ;
  317.        pvbuf[2] = AL_RIGHT_SPEAKER_GAIN ;
  318.        pvbuf[3] = pvbuf[1] ;
  319.        ALsetparams(AL_DEFAULT_DEVICE, pvbuf, 4);
  320.  
  321.        Counter.shmad[0] = pvbuf[1] ;
  322.        }
  323. #endif
  324.   
  325.      c1 = fcos(Dyaw) ;
  326.      s1 = fsin(Dyaw) ;
  327.      c2 = fcos(Dpitch) ;
  328.      s2 = fsin(Dpitch) ;
  329.      c3 = fcos(Droll) ;
  330.      s3 = fsin(Droll) ;
  331.  
  332.      m[0][0] =  c1*c3+s3*s2*s1 ; m[0][1] =  s3*c2 ; m[0][2] = -c3*s1+s3*s2*c1 ; m[0][3] =  0.0 ;
  333.      m[1][0] = -s3*c1+c3*s2*s1 ; m[1][1] =  c3*c2 ; m[1][2] =  s1*s3+c3*s2*c1 ; m[1][3] =  0.0 ;
  334.      m[2][0] =  c2*s1          ; m[2][1] = -s2    ; m[2][2] =  c1*c2          ; m[2][3] =  0.0 ;
  335.      m[3][0] =  0.0            ; m[3][1] =  0.0   ; m[3][2] =  0.0            ; m[3][3] =  1.0 ;
  336.   
  337.      spMultMatrix((flot32 *)Counter.mat,(flot32 *)Counter.mat,(flot32 *)m) ;
  338.   
  339.      for (c=Counter.clop,i=0; i<NUM_CLIP_PLANES; c++,i++)  {
  340.        c->x = Counter.mat[0][0]*raww[i].x + Counter.mat[0][1]*raww[i].y + Counter.mat[0][2]*raww[i].z ;
  341.        c->y = Counter.mat[1][0]*raww[i].x + Counter.mat[1][1]*raww[i].y + Counter.mat[1][2]*raww[i].z ;
  342.        c->z = Counter.mat[2][0]*raww[i].x + Counter.mat[2][1]*raww[i].y + Counter.mat[2][2]*raww[i].z ;
  343.        c->w = ((Counter.status == STELL_STAT) ? 0.0 : -c->x*Counter.eye.x-c->y*Counter.eye.y-c->z*Counter.eye.z) ;
  344.        }
  345.  
  346.      if (!(Counter.flags & AUTOP_FLAG))  {
  347.        vel = Counter.S * ((Counter.status != STELL_STAT) ? PRTOKM : 1.0) ;
  348.  
  349.        if (lm && !mm && !rm) {
  350.          if (vel > 0.80*LIGHTSPEED && vel < 0.999*LIGHTSPEED)
  351.            vel += 0.08*(LIGHTSPEED-vel) ;
  352.          else vel *= 1.1;
  353.          Counter.attach = 0 ;
  354.          }
  355.        if (mm && !lm && !rm)  {
  356.          if (vel > LIGHTSPEED && vel < 1.1*LIGHTSPEED)
  357.            vel = 0.9985*LIGHTSPEED ;
  358.          else if (vel > 0.80*LIGHTSPEED && vel < 0.999*LIGHTSPEED)
  359.            vel -= 0.08*(LIGHTSPEED-vel) ;
  360.          else vel /= 1.1;
  361.          }
  362.  
  363.        Counter.S = vel / ((Counter.status != STELL_STAT) ? PRTOKM : 1.0) ;
  364.        }
  365.  
  366.      if (Counter.alpha & HW_SOUND)  {
  367.        vel = Counter.S * ((Counter.status != STELL_STAT) ? PRTOKM : 1.0) ;
  368.        Counter.shmad[1] = ((vel >= LIGHTSPEED) ? 1 : 0) ;
  369.        }
  370.  
  371.      Counter.enorm.x = -Counter.mat[0][2];
  372.      Counter.enorm.y = -Counter.mat[1][2];
  373.      Counter.enorm.z = -Counter.mat[2][2];
  374.   
  375.      if (!(Counter.flags & CNTRL_FLAG))  {
  376.        Counter.vnorm.x = Counter.enorm.x ;
  377.        Counter.vnorm.y = Counter.enorm.y ;
  378.        Counter.vnorm.z = Counter.enorm.z ;
  379.        }
  380.      }
  381.  
  382.    if (Counter.flags & AUTOP_FLAG)  {
  383.      Counter.attach = 0 ;
  384.      take_me_there(&Counter.spline) ;
  385.      }
  386.   
  387.    if (Counter.attach) {
  388.      Counter.eye.x += flaggs->stat.posit.x - 500.0 ;
  389.      Counter.eye.y += flaggs->stat.posit.y ;
  390.      Counter.eye.z += flaggs->stat.posit.z ;
  391.      }
  392.    else if (!(Counter.flags & AUTOP_FLAG))  {
  393.      c1 = Counter.S * ((Counter.flags & VELOC_FLAG) ? -1.0 : 1.0) * (Counter.timer - Counter.timer_old) ;
  394.  
  395.      if (!(Counter.flags & FREEZ_FLAG))  {
  396.        Counter.eye.x += Counter.vnorm.x*c1 ;
  397.        Counter.eye.y += Counter.vnorm.y*c1 ;
  398.        Counter.eye.z += Counter.vnorm.z*c1 ;
  399.        }
  400.      }
  401.  
  402.    Counter.flags &= ~FREEZ_FLAG ;
  403. }
  404.  
  405. /********************************************************************** 
  406. *  key_press()  -  
  407. **********************************************************************/
  408. void key_press(t_boss *flaggs,sint32 v)
  409.  
  410. {  char ch[64];
  411.  
  412.    switch(v)  {
  413.      case SP_IO_esc : printf("Total Frames = %d\n",Counter.click) ;
  414.                       if (Counter.alpha & HW_SOUND)
  415.                         sound_control(0,0) ;
  416.                       if (Counter.alpha & HW_SOUND)
  417.                         shmdt(Counter.shmad) ;
  418.                       exit(1); 
  419.                       break ;
  420.   
  421.      case SP_IO_a   : if (Counter.flags & AUTOP_FLAG)  {
  422.                         Counter.flags &= ~AUTOP_FLAG ;
  423.                         if (Counter.flags & PANEL_FLAG)
  424.                          draw_item(SP_IO_a,0) ;
  425.                         break ;
  426.                         }
  427.  
  428.                       if (!autopilot_menu_stuff(flaggs))
  429.                         break;
  430.    
  431.                       if (Counter.flags & TMREV_FLAG) {
  432.                         Counter.flags &= ~TMREV_FLAG ;
  433.    
  434.                         if (Counter.flags & PANEL_FLAG)
  435.                           draw_item(SP_IO_a,0) ;
  436.                         }
  437.                       if (Counter.timacc < 1.0)  {
  438.                         Counter.timacc = 1.0 ;
  439.                         if (Counter.flags & PANEL_FLAG)
  440.                           draw_item(SP_IO_tco,0) ;
  441.                         }
  442.                       else if (Counter.timacc > 10.0)  {
  443.                         Counter.timacc = 10.0 ;
  444.                         if (Counter.flags & PANEL_FLAG)
  445.                           draw_item(SP_IO_tco,0) ;
  446.                         }
  447.    
  448.                       if (Counter.flags & PANEL_FLAG)
  449.                         draw_item(SP_IO_a,0) ;
  450.                       break ;
  451.    
  452.      case SP_IO_s   : if (Counter.status != STELL_STAT)
  453.                         break ;
  454.  
  455.                       if (Counter.flags & STATS_FLAG)
  456.                         Counter.flags &= ~STATS_FLAG ;
  457.                       else Counter.flags |= STATS_FLAG ;
  458.    
  459.                       if (Counter.flags & PANEL_FLAG)
  460.                         draw_item(SP_IO_s,0) ;
  461.    
  462.                       stats_menu_stuff(flaggs);
  463.    
  464.                       if (Counter.flags & STATS_FLAG)
  465.                         Counter.flags &= ~STATS_FLAG ;
  466.                       else Counter.flags |= STATS_FLAG ;
  467.    
  468.                       if (Counter.flags & PANEL_FLAG)
  469.                         draw_item(SP_IO_s,0) ;
  470.                       break ;
  471.    
  472.      case SP_IO_x   : if (Counter.flags & NOTXT_FLAG)
  473.                         Counter.flags &= ~NOTXT_FLAG ;
  474.                       else Counter.flags |= NOTXT_FLAG ;
  475.    
  476.                       if (Counter.flags & PANEL_FLAG)
  477.                         draw_item(v,0) ;
  478.                       break ;
  479.  
  480.      case SP_IO_h   : if (Counter.flags & HELPP_FLAG)
  481.                         Counter.flags &= ~HELPP_FLAG ;
  482.                       else Counter.flags |= HELPP_FLAG ;
  483.    
  484.                       if (Counter.flags & PANEL_FLAG)
  485.                         draw_item(v,0) ;
  486.                       break ;
  487.       
  488.      case SP_IO_l   : if (Counter.flags & SHADE_FLAG)
  489.                         Counter.flags &= ~SHADE_FLAG ;
  490.                       else Counter.flags |= SHADE_FLAG ;
  491.  
  492.                       if (Counter.flags & PANEL_FLAG)
  493.                         draw_item(v,0) ;
  494.                       break ;
  495.  
  496.      case SP_IO_v   : if (Counter.flags & VELOC_FLAG)
  497.                         Counter.flags &= ~VELOC_FLAG ;
  498.                       else Counter.flags |= VELOC_FLAG ;
  499.  
  500.                       if (Counter.flags & PANEL_FLAG)
  501.                         draw_item(v,0) ;
  502.                       break ;
  503.  
  504.      case SP_IO_d   : if (Counter.flags & DEBUG_FLAG)
  505.                         Counter.flags &= ~DEBUG_FLAG ;
  506.                       else Counter.flags |= DEBUG_FLAG ;
  507.                       break ;
  508.  
  509.      case SP_IO_i   : if (Counter.flags & MRBIT_FLAG)
  510.                         Counter.flags &= ~MRBIT_FLAG ;
  511.                       else Counter.flags |= MRBIT_FLAG ;
  512.  
  513.                       if (Counter.flags & PANEL_FLAG)
  514.                         draw_item(v,0) ;
  515.                       break ;
  516.  
  517.      case SP_IO_o   : if (Counter.flags & PRBIT_FLAG)
  518.                         Counter.flags &= ~PRBIT_FLAG ;
  519.                       else Counter.flags |= PRBIT_FLAG ;
  520.  
  521.                       if (Counter.flags & PANEL_FLAG)
  522.                         draw_item(v,0) ;
  523.                       break ;
  524.  
  525.      case SP_IO_tid : if (Counter.flags & TMREV_FLAG)
  526.                         Counter.flags &= ~TMREV_FLAG ;
  527.                       else Counter.flags |= TMREV_FLAG ;
  528.  
  529.                       if (Counter.flags & PANEL_FLAG)
  530.                         draw_item(v,0) ;
  531.                       break ;
  532.  
  533.      case SP_IO_u   : if (Counter.flags & USERM_FLAG)
  534.                         Counter.flags &= ~USERM_FLAG ;
  535.                       else Counter.flags |= USERM_FLAG ;
  536.                       break ;
  537.  
  538.      case SP_IO_pri : if (Counter.flags & PRINT_FLAG)
  539.                         Counter.flags &= ~PRINT_FLAG ;
  540.                       else Counter.flags |= PRINT_FLAG ;
  541.  
  542.                       if (Counter.flags & PANEL_FLAG)
  543.                         draw_item(v,0) ;
  544.                       break ;
  545.  
  546.      case SP_IO_n   : if (Counter.flags & STNAM_FLAG)
  547.                         Counter.flags &= ~STNAM_FLAG ;
  548.                       else Counter.flags |= STNAM_FLAG ;
  549.  
  550.                       if (Counter.flags & PANEL_FLAG)
  551.                         draw_item(v,0) ;
  552.                       break ;
  553.  
  554.      case SP_IO_snd : if (Counter.flags & SOUND_FLAG)  {
  555.                         Counter.flags &= ~SOUND_FLAG ;
  556.                         if (Counter.alpha & HW_SOUND)
  557.                           sound_control(0,0) ;
  558.                         }
  559.                       else  {
  560.                         Counter.flags |= SOUND_FLAG ;
  561.                         if ((Counter.alpha & HW_SOUND) && (Counter.flags & SOUND_FLAG))
  562.                           sound_control(1,SND_BACK) ;
  563.                         }
  564.                       break ;
  565.  
  566.      case SP_IO_b   : if (Counter.flags & HIRES_FLAG)  {
  567.                         Counter.flags &= ~HIRES_FLAG ;
  568. #if STATS
  569.                         statistics(0);
  570. #endif
  571.                         if (Counter.winst.hwid & (SP_HW_XG | SP_HW_LG))
  572.                           Counter.flags &= ~TEXTR_FLAG;
  573.                         }
  574.                       else  {
  575.                         Counter.flags |= HIRES_FLAG ;
  576.                         if (Counter.winst.hwid & (SP_HW_XG | SP_HW_LG))
  577.                           Counter.flags |= TEXTR_FLAG;
  578. #if STATS
  579.                         statistics(1);
  580. #endif
  581.                         }
  582.    
  583.                       if (Counter.flags & PANEL_FLAG)
  584.                         draw_menu() ;
  585.                       break ;
  586.  
  587.      case SP_IO_z   : if (Counter.flags & ZODAC_FLAG)
  588.                         Counter.flags &= ~ZODAC_FLAG ;
  589.                       else Counter.flags |= ZODAC_FLAG ;
  590.  
  591.                       if (Counter.flags & PANEL_FLAG)
  592.                         draw_item(v,0) ;
  593.                       break ;
  594.  
  595.      case SP_IO_t   : Counter.timacc *= 10.0 ;
  596.                       if (Counter.timacc > 1.0e11)
  597.                         Counter.timacc =  1.0e11 ;
  598.                       else if (Counter.timacc == 0.0)
  599.                         Counter.timacc = 0.01 ;
  600.    
  601.                       if (Counter.flags & PANEL_FLAG)
  602.                         draw_item(SP_IO_tco,0) ;
  603.                       break ;
  604.  
  605.      case SP_IO_r   : Counter.timacc *= 0.1 ;
  606.                       if (Counter.timacc < 0.0099)
  607.                         Counter.timacc = 0.0 ;
  608.    
  609.                       if (Counter.flags & PANEL_FLAG)
  610.                         draw_item(SP_IO_tco,0) ;
  611.                       break ;
  612.  
  613.      case SP_IO_y   : timer_flag = 0 ;
  614.                       Counter.timacc = 1.0 ;
  615.                       Counter.timer_old = check_timer() ;
  616.                       Counter.timer     = check_timer() ;
  617.    
  618.                       if (Counter.flags & PANEL_FLAG)
  619.                         draw_item(SP_IO_tco,0) ;
  620.                       break ;
  621.     
  622.      case SP_IO_dwn : Counter.hw_graphics-- ;
  623.                       Counter.flags |= REGEN_FLAG ;
  624.                       break ;
  625.  
  626.      case SP_IO_up  : Counter.hw_graphics++ ;
  627.                       Counter.flags |= REGEN_FLAG ;
  628.                       break ;
  629.  
  630.      case SP_IO_q   : if (Counter.flags & PANEL_FLAG)
  631.                         Counter.flags &= ~PANEL_FLAG ;
  632.                       else Counter.flags |= PANEL_FLAG ;
  633.  
  634.                       set_window_view(300.0) ;
  635.                       draw_menu() ;
  636.                       break ;
  637.  
  638.      case SP_IO_tco : draw_item(SP_IO_tco,0) ;
  639.                       break ;
  640.  
  641.      default        : break ; 
  642.      }
  643. }
  644.  
  645. /**********************************************************************
  646. *  el_cheato()  -
  647. **********************************************************************/
  648. static void el_cheato(t_boss *flaggs,sint32 flag,Matrix m)
  649.  
  650. {  register D3     p ;
  651.    register t_body *tb,*tc ;
  652.    register flot32 x,y,z ;
  653.             sint32 index ;
  654.  
  655.    switch (flag)  {
  656.      case  0 : if (Counter.status == STELL_STAT)  {
  657.                  p = flaggs->star[flaggs->suun_current].posit ;
  658.                  spLookMatrix(0.0,0.0,0.0,(flot32)p.x,(flot32)p.y,(flot32)p.z,m) ;
  659.                  }
  660.                else if (Counter.status == GALAC_STAT)  {
  661.                  register t_galaga *ga = &ggaa[Counter.z][Counter.x] ;
  662.  
  663.                  find_closest_star(&index,ga) ;
  664.                  if (index < 0)
  665.                    break ;
  666.  
  667.                  x = ga->stars[index].x - 0.5*GALAXY_EDGE + (Counter.x+0.5)*EDGESQ ;
  668.                  y = ga->stars[index].y ;
  669.                  z = ga->stars[index].z - 0.5*GALAXY_EDGE + (Counter.z+0.5)*EDGESQ ;
  670.  
  671.                  spLookMatrix(Counter.eye.x,Counter.eye.y,Counter.eye.z,x,y,z,m) ;
  672.                  }
  673.                else if (Counter.status == COSMC_STAT) 
  674.                  spLookMatrix(Counter.eye.x,Counter.eye.y,Counter.eye.z,0.0,0.0,0.0,m) ;
  675.  
  676.                break ;
  677.  
  678.      case  1 : if (Counter.status != STELL_STAT || flaggs->plan_current == -1)
  679.                  return ;
  680.                tb = (t_body *) flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  681.                p = tb->posit ;
  682.  
  683.                spLookMatrix(0.0,0.0,0.0,(flot32)p.x,(flot32)p.y,(flot32)p.z,m) ;
  684.                break ;
  685.  
  686.      case  2 : if (Counter.status != STELL_STAT || flaggs->plan_current == -1 || flaggs->moon_current == -1)
  687.                  return ;
  688.                tb = (t_body *) flaggs->star[flaggs->suun_current].next[flaggs->plan_current] ;
  689.                tc = (t_body *) tb->next[flaggs->moon_current] ;
  690.                p = tc->posit ;
  691.  
  692.                spLookMatrix(0.0,0.0,0.0,(flot32)p.x,(flot32)p.y,(flot32)p.z,m) ;
  693.                break ;
  694.  
  695.      case  3 : if (Counter.status == STELL_STAT && flaggs->suncount == 2)  {
  696.                  if (flaggs->suun_current == 1)
  697.                    p = flaggs->star[0].posit ;
  698.                  else p = flaggs->star[1].posit ;
  699.  
  700.                  spLookMatrix(0.0,0.0,0.0,(flot32)p.x,(flot32)p.y,(flot32)p.z,m) ;
  701.                  }
  702.                break ;
  703.  
  704.      default : break ;
  705.      }
  706. }
  707.  
  708. /********************************************************************** 
  709. *  take_me_there()  -  
  710. **********************************************************************/
  711. static void take_me_there(t_spline *tsp)
  712.  
  713. {  register flot64 t,a,b,c,d ;
  714.  
  715.    t = (Counter.D - tsp->t1) / (tsp->t2 - tsp->t1) ;
  716.  
  717.    if (t < 0.0)  {
  718.      printf("USER ERROR: Something fishy about the flow of time.\n") ;
  719.      Counter.flags &= ~AUTOP_FLAG ;
  720.      if (Counter.flags & PANEL_FLAG)
  721.        draw_item(SP_IO_a,0) ;
  722.      }
  723.    else if (t >= 1.0 || (Counter.star_current == tsp->newstar[0] && Counter.x == tsp->newstar[1] && Counter.z == tsp->newstar[2]))  {
  724.      Counter.flags &= ~AUTOP_FLAG ;
  725.      if (Counter.flags & PANEL_FLAG)
  726.        draw_item(SP_IO_a,0) ;
  727.  
  728.      if (Counter.spline.newstar[0] != -2)  {
  729.        Counter.S = 100000.0*LIGHTSPEED ;
  730.        if (Counter.status != STELL_STAT)
  731.          Counter.S *= KMTOPR ;
  732.        }
  733.      else Counter.S = 100.0 ;
  734.  
  735.      spRingBell() ;
  736.      }
  737.    else  {
  738.      if (t <= 0.5)
  739.        t = 2.0*t*t ;
  740.      else t = -2.0*(t-1.0)*(t-1.0) + 1.0 ;
  741.  
  742.      a = ((hermite[0][0]*t + hermite[0][1])*t + hermite[0][2])*t + hermite[0][3] ;
  743.      b = ((hermite[1][0]*t + hermite[1][1])*t + hermite[1][2])*t + hermite[1][3] ;
  744.      c = ((hermite[2][0]*t + hermite[2][1])*t + hermite[2][2])*t + hermite[2][3] ;
  745.      d = ((hermite[3][0]*t + hermite[3][1])*t + hermite[3][2])*t + hermite[3][3] ;
  746.  
  747.      Counter.eye.x = tsp->p1.x*a + tsp->p2.x*b + tsp->v1.x*c + tsp->v2.x*d ;
  748.      Counter.eye.y = tsp->p1.y*a + tsp->p2.y*b + tsp->v1.y*c + tsp->v2.y*d ;
  749.      Counter.eye.z = tsp->p1.z*a + tsp->p2.z*b + tsp->v1.z*c + tsp->v2.z*d ;
  750.      }
  751. }
  752.  
  753. /**********************************************************************
  754. *  scan_galactic_system()  - 
  755. **********************************************************************/
  756. void scan_galactic_system(t_boss *flaggs)
  757.  
  758. {           sint32  q,index,count ;
  759.    register flot32  d,x,y,z ;
  760.    register D3      *eye = &Counter.eye ;
  761.  
  762.    /* currently in stellar system */
  763.    if (Counter.status == STELL_STAT)  {
  764.      if (eye->x*eye->x + eye->y*eye->y + eye->z*eye->z >= SOLSYS_EDGE*PRTOKM*PRTOKM)  {
  765.        register t_stars *st = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  766.  
  767.        eye->x = eye->x*KMTOPR + st->x + -0.5*GALAXY_EDGE + (Counter.x+0.5)*EDGESQ ;
  768.        eye->y = eye->y*KMTOPR + st->y ;
  769.        eye->z = eye->z*KMTOPR + st->z + -0.5*GALAXY_EDGE + (Counter.z+0.5)*EDGESQ ;
  770.        Counter.S *= KMTOPR ; 
  771.  
  772.        if (Counter.flags & AUTOP_FLAG)  {
  773.          register t_galaga *ga = &ggaa[Counter.spline.newstar[2]][Counter.spline.newstar[1]] ;
  774.  
  775.          Counter.spline.p1.x = eye->x ;
  776.          Counter.spline.p1.y = eye->y ;
  777.          Counter.spline.p1.z = eye->z ;
  778.  
  779.          Counter.spline.v1.x *= KMTOPR ;
  780.          Counter.spline.v1.y *= KMTOPR ;
  781.          Counter.spline.v1.z *= KMTOPR ;
  782.  
  783.          Counter.spline.p2.x = ga->stars[Counter.spline.newstar[0]].x - 0.5*GALAXY_EDGE + (Counter.spline.newstar[1]+0.5)*EDGESQ ;
  784.          Counter.spline.p2.y = ga->stars[Counter.spline.newstar[0]].y ;
  785.          Counter.spline.p2.z = ga->stars[Counter.spline.newstar[0]].z - 0.5*GALAXY_EDGE + (Counter.spline.newstar[2]+0.5)*EDGESQ ;
  786.  
  787.          Counter.spline.v2.x *= KMTOPR ;
  788.          Counter.spline.v2.y *= KMTOPR ;
  789.          Counter.spline.v2.z *= KMTOPR ;
  790.          }
  791.  
  792.        destroy_solar_system(flaggs) ;
  793.  
  794.        Counter.star_current = -1 ;
  795.        Counter.status = GALAC_STAT ;
  796.        Counter.infoco = GALAC_COLR ;
  797.        }
  798.      else  {
  799.        Counter.status = STELL_STAT ;
  800.        Counter.infoco = STELL_COLR ;
  801.        scan_star_system(flaggs) ;
  802.        }
  803.      }
  804.  
  805.    /* currently in galactic system */
  806.    else if (Counter.status == GALAC_STAT)  {
  807.      Counter.x = (flot32) 0.5*STARSQ + eye->x/EDGESQ ;
  808.      Counter.y = (flot32)              eye->y/EDGESQ ;
  809.      Counter.z = (flot32) 0.5*STARSQ + eye->z/EDGESQ ;
  810.  
  811.      if (eye->x*eye->x+eye->z*eye->z > 0.25*GALAXY_EDGE*GALAXY_EDGE || eye->y*eye->y > HEIGHT_ABOVE)  {
  812.        printf("Leaving galaxy\n") ;
  813.        Counter.star_current = -1 ;
  814.        Counter.status = COSMC_STAT ;
  815.        Counter.infoco = COSMC_COLR ;
  816.        }
  817.      else  {
  818.        q = find_closest_star(&index,&ggaa[Counter.z][Counter.x]) ;
  819.  
  820.        if (q == STELL_STAT)  {
  821.          register t_stars *st ;
  822.  
  823.          if (glIsList(Counter.locun))
  824.            glDeleteLists(Counter.locun,1);
  825.  
  826.          Counter.infoco = STELL_COLR ;
  827.          Counter.status = STELL_STAT ;
  828.  
  829.          if (Counter.x == SOL_X_GRID && Counter.z == SOL_Z_GRID)
  830.            printf("New Star: %d  Name: %s\n",index,StarName[index]) ;
  831.          else printf("New Star: %d-%d,%d\n",index,Counter.x,Counter.z) ;
  832.  
  833.          create_solar_system(index,flaggs,&ggaa[Counter.z][Counter.x]) ;
  834.          Counter.star_current = index ;
  835.  
  836.          Counter.locun = glGenLists(1);
  837.          glNewList(Counter.locun,GL_COMPILE) ;
  838.          draw_all_them_stars(0);
  839.          glEndList();
  840.  
  841.          st = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  842.          eye->x = PRTOKM*(eye->x - (-0.5*GALAXY_EDGE + (Counter.x+0.5)*EDGESQ + st->x)) ;
  843.          eye->y = PRTOKM*(eye->y - (                                            st->y)) ;
  844.          eye->z = PRTOKM*(eye->z - (-0.5*GALAXY_EDGE + (Counter.z+0.5)*EDGESQ + st->z)) ;
  845.          Counter.S = 100000.0*LIGHTSPEED ;
  846.  
  847.          scan_star_system(flaggs) ;
  848.          }
  849.        else  {
  850.          Counter.status = GALAC_STAT ;
  851.          Counter.infoco = GALAC_COLR ;
  852.          }
  853.        }
  854.      }
  855.  
  856.    /* currently in cosmic system */
  857.    else if (Counter.status == COSMC_STAT)  {
  858.      Counter.x = (flot32) 0.5*STARSQ + eye->x/EDGESQ ;
  859.      Counter.y = (flot32)              eye->y/EDGESQ ;
  860.      Counter.z = (flot32) 0.5*STARSQ + eye->z/EDGESQ ;
  861.  
  862.      if (eye->x*eye->x+eye->z*eye->z < 0.25*GALAXY_EDGE*GALAXY_EDGE && eye->y*eye->y < HEIGHT_ABOVE)  {
  863.        printf("Entering galaxy\n") ;
  864.        Counter.star_current = -1 ;
  865.        Counter.infoco = GALAC_COLR ;
  866.        Counter.status = GALAC_STAT ;
  867.        }
  868.      else  {
  869.        Counter.infoco = COSMC_COLR ;
  870.        Counter.status = COSMC_STAT ;
  871.        }
  872.      }
  873.    else  {
  874.      printf("INTERNAL ERROR: Unsupported case in scan_galactic_system()\n") ;
  875.      exit(0) ;
  876.      }
  877. }
  878.  
  879. /**********************************************************************
  880. *  init_stars()  - 
  881. **********************************************************************/
  882. static void init_stars(void)
  883.  
  884. {  register sint32  i,j ;
  885.    register FILE    *fdi ;
  886.    register t_stars *st ;
  887.             flot32  q[2],d,rmag,rmag2 ;
  888.             flot64  u[2] ;
  889.    register char    code[4],*su,c ;
  890.  
  891.    printf("Loading stellar database\n") ;
  892.    if ((fdi = fopen(datatrail("star.db"),"r")) == NULL)  {
  893.      printf("USER ERROR: Star database file not found: %s\n",datatrail("star.db")) ;
  894.      exit(0) ;
  895.      }
  896.  
  897.    st = erikl ;
  898.    su = StarName[0] ;
  899.  
  900.    st->x    = 0.0 ;
  901.    st->y    = 0.0 ;
  902.    st->z    = 0.0 ;
  903.    st->abs_mag = 4.83 ;
  904.    st->fny_mag = exp(LN2*(6.0 - st->abs_mag)) ;
  905.    st->scass = 0.34 ;
  906.    st->abs_mag2 = 0.0;
  907.    st->scass2   = 0.0;
  908.    star_params(st,q,q,u) ;
  909.    strcpy(su,"Sol") ;
  910.  
  911.    for (st++,su+=16,i=1; i<NUMBER_OF_STARS; st++,su+=16,i++)  {
  912.      fscanf(fdi,"%f %f %f %f %c%c%c%c",&st->x,&st->y,&st->z,&rmag,&code[0],&code[1],&code[2],&code[3]) ;
  913.  
  914.      if (code[2] != '.')
  915.        fscanf(fdi,"%f",&rmag2);
  916.      else rmag2 = 0.0;
  917.  
  918.      for (j=0,c=getc(fdi); c != '\n' && c != '\0'; c=getc(fdi))
  919.        if (j != 0 || c != ' ')
  920.          su[j++] = c ;
  921.      su[j] = '\0' ;
  922.  
  923.      d = st->x*st->x + st->y*st->y + st->z*st->z ;
  924.      st->abs_mag  = rmag + 5.0 - 2.5*log10(d) ;
  925.      st->fny_mag  = exp(LN2*(6.0 - st->abs_mag)) ;
  926.  
  927.      switch(code[0])  {
  928.        case 'W' : st->scass = 0.99 ; break ;
  929.        case 'O' : st->scass = 0.95 ; break ;
  930.        case 'B' : st->scass = 0.70 ; break ;
  931.        case 'A' : st->scass = 0.55 ; break ;
  932.        case 'F' : st->scass = 0.41 ; break ;
  933.        case 'G' : st->scass = 0.32 ; break ;
  934.        case 'K' : st->scass = 0.19 ; break ;
  935.        case 'M' : st->scass = 0.05 ; break ;
  936.        case 'S' : st->scass = 0.04 ; break ;
  937.        case 'R' : st->scass = 0.03 ; break ;
  938.        case 'N' : st->scass = 0.02 ; break ;
  939.        case 'C' : st->scass = 0.01 ; break ;
  940.        case 'P' : st->scass = 0.01 ; break ;
  941.        default  : printf("INTERNAL ERROR: Star Fuckup %d (%c)\n",i,code[0]) ;
  942.                   exit(0);
  943.                   break ;
  944.        }
  945.  
  946.      if (code[2] != '.')  {
  947.        st->abs_mag2 = rmag2 + 5.0 - 2.5*log10(d) ;
  948.  
  949.        switch(code[2])  {
  950.          case 'W' : st->scass2 = 0.99 ; break ;
  951.          case 'O' : st->scass2 = 0.95 ; break ;
  952.          case 'B' : st->scass2 = 0.70 ; break ;
  953.          case 'A' : st->scass2 = 0.55 ; break ;
  954.          case 'F' : st->scass2 = 0.41 ; break ;
  955.          case 'G' : st->scass2 = 0.32 ; break ;
  956.          case 'K' : st->scass2 = 0.19 ; break ;
  957.          case 'M' : st->scass2 = 0.05 ; break ;
  958.          case 'S' : st->scass2 = 0.04 ; break ;
  959.          case 'R' : st->scass2 = 0.03 ; break ;
  960.          case 'N' : st->scass2 = 0.02 ; break ;
  961.          case 'C' : st->scass2 = 0.01 ; break ;
  962.          case 'P' : st->scass2 = 0.01 ; break ;
  963.          default  : printf("INTERNAL ERROR: Binary Star Fuckup %d (%c)\n",i,code[2]) ;
  964.                     exit(0);
  965.                     break ;
  966.          }
  967.        }
  968.      else  {
  969.        st->abs_mag2 = 0.0;
  970.        st->scass2   = 0.0;
  971.        }
  972.  
  973.      star_params(st,q,q,u) ;
  974.      }
  975. }
  976.  
  977. /**********************************************************************
  978. *  init_cnstl()  - 
  979. **********************************************************************/
  980. static sint32 init_cnstl(void)
  981.  
  982. {  sint32  i,j,count,obj ;
  983.    FILE    *fd ;
  984.    flot32  x,y,z,a,b,c1,s1 ;
  985.    P4      *c ;
  986.    t_bordr *br ;
  987.    Matrix  mb ;
  988.  
  989.    if (!(fd = fopen(datatrail("const.db"),"r")))  {
  990.      printf("USER ERROR: Constellation database file not found: %s\n",datatrail("const.db")) ;
  991.      exit(0) ;
  992.      }
  993.  
  994.    c1 = fcos(DTOR*23.5) ;
  995.    s1 = fsin(DTOR*23.5) ;
  996.    mb[0][0] =  c1 ; mb[0][1] =  s1 ; mb[0][2] = 0.0 ; mb[0][3] = 0.0 ;
  997.    mb[1][0] = -s1 ; mb[1][1] =  c1 ; mb[1][2] = 0.0 ; mb[1][3] = 0.0 ;
  998.    mb[2][0] = 0.0 ; mb[2][1] = 0.0 ; mb[2][2] = 1.0 ; mb[2][3] = 0.0 ;
  999.    mb[3][0] = 0.0 ; mb[3][1] = 0.0 ; mb[3][2] = 0.0 ; mb[3][3] = 1.0 ;
  1000.  
  1001.    fscanf(fd,"%d",&constellation.arr_count) ;
  1002.  
  1003.    for (c=constellation.arr,i=0; i<constellation.arr_count; c++,i++)  {
  1004.      fscanf(fd,"%f %f",&x,&y) ;
  1005.  
  1006.      a = 2.0 * M_PI * (0.0 - x) ;
  1007.      b = M_PI * (y - 0.5) ;
  1008.  
  1009.      x = PRTOKM * fcos(b) * fsin(a) ; 
  1010.      y = PRTOKM * fsin(b) ;
  1011.      z = PRTOKM * fcos(b) * fcos(a) ; 
  1012.  
  1013.      c->x = mb[0][0]*x + mb[0][1]*y + mb[0][2]*z ;
  1014.      c->y = mb[1][0]*x + mb[1][1]*y + mb[1][2]*z ;
  1015.      c->z = mb[2][0]*x + mb[2][1]*y + mb[2][2]*z ;
  1016.      }
  1017.  
  1018.    fscanf(fd,"%d",&constellation.brd_count) ;
  1019.  
  1020.    for (br=constellation.brd,i=0; i<constellation.brd_count; br++,i++)  {
  1021.      fscanf(fd,"%d",&br->count) ;
  1022.      for (j=0; j<br->count; j++) 
  1023.        fscanf(fd,"%d",&br->index[j]) ;
  1024.      fscanf(fd,"%f %f %s",&x,&y,br->name) ;
  1025.  
  1026.      a = 2.0 * M_PI * (0.0 - x) ;
  1027.      b = M_PI * (y - 0.5) ;
  1028.  
  1029.      x = PRTOKM * fcos(b) * fsin(a) ; 
  1030.      y = PRTOKM * fsin(b) ;
  1031.      z = PRTOKM * fcos(b) * fcos(a) ; 
  1032.  
  1033.      br->x = mb[0][0]*x + mb[0][1]*y + mb[0][2]*z ;
  1034.      br->y = mb[1][0]*x + mb[1][1]*y + mb[1][2]*z ;
  1035.      br->z = mb[2][0]*x + mb[2][1]*y + mb[2][2]*z ;
  1036.      }
  1037.  
  1038.    fclose(fd) ;
  1039.  
  1040.    obj = glGenLists(1);
  1041.    glNewList(obj,GL_COMPILE) ;
  1042.    glColor4f(1.0,0.0,0.0,1.0);
  1043.  
  1044.    for (br=constellation.brd,i=0; i<constellation.brd_count; br++,i++) {
  1045.      glBegin(GL_LINE_LOOP) ;
  1046.      for (j=0; j<br->count; j++)
  1047.        glVertex3fv(&constellation.arr[br->index[j]].x) ;
  1048.      glEnd() ;
  1049.  
  1050.      spDrawString(br->x,br->y,br->z,br->name) ;
  1051.      }
  1052.  
  1053.    glEndList();
  1054.    return(obj) ;
  1055. }
  1056.  
  1057. /********************************************************************** 
  1058. *  generate_star_squares()  -  
  1059. **********************************************************************/
  1060. static void generate_star_squares()
  1061.  
  1062. {  register sint32   i,j,k,m,temp[3],index ;
  1063.    register flot32   *fd = (flot32 *) temp ;
  1064.    register t_stars  *st ;
  1065.    register t_galaga *ga ;
  1066.             flot32   q ;
  1067.             flot64   u ;
  1068.  
  1069.    srand(0x2468) ;
  1070.  
  1071.    for (st=dodo,i=0; i<DODO_SIZE; st++,i++)  {
  1072.      temp[0] = 0x3f800000 | ((j=rand()) << 8) ;
  1073.      temp[1] = 0x3f800000 | ((k=rand()) << 8) ;
  1074.      temp[2] = 0x3f800000 | ((m=rand()) << 8) ;
  1075.  
  1076.      st->x = (fd[0] - 1.5) * EDGESQ ;
  1077.      st->y = (fd[1] - 1.5) * 8.0*EDGESQ ;
  1078.      st->z = (fd[2] - 1.5) * EDGESQ ;
  1079.  
  1080.      st->abs_mag = 8 - (k & 0xf) ;
  1081.      st->fny_mag = exp(LN2*(6.0 - st->abs_mag)) ;
  1082.      temp[0] = 0x3f800000 | (rand() << 8) ;
  1083.      st->scass = fd[0] - 1.0 ;
  1084.      st->scass *= st->scass ;
  1085.  
  1086.      if ((rand() & 3) == 3)  {
  1087.        st->abs_mag2 = 8 - (m & 0xf) ;
  1088.        temp[0] = 0x3f800000 | (rand() << 8) ;
  1089.        st->scass2 = fd[0] - 1.0 ;
  1090.        st->scass2 *= st->scass2 ;
  1091.        }
  1092.      else  {
  1093.        st->abs_mag2 = 0.0;
  1094.        st->scass2   = 0.0;
  1095.        }
  1096.  
  1097.      star_params(st,&q,&q,&u) ;
  1098.      }
  1099.  
  1100.    for (ga=ggaa[0],i=0; i<STARSQ; i++) 
  1101.      for (j=0; j<STARSQ; ga++,j++)  {
  1102.        ga->count = (Counter.stars_per_square * ga->count) / 1024.0 ;
  1103.        if (ga->count < 2)
  1104.          ga->count == 0 ;
  1105.  
  1106.        temp[0] = 0x3f800000 | (rand() << 8) ;
  1107.        fd[0] = (fd[0] - 1.0) ;
  1108.        fd[0] *= (DODO_SIZE - ga->count) ;
  1109.        ga->stars = &dodo[(sint32)fd[0]] ;
  1110.        }
  1111.  
  1112.    ggaa[Counter.z][Counter.x].count = NUMBER_OF_STARS ;
  1113.    ggaa[Counter.z][Counter.x].stars = erikl ;
  1114. }
  1115.  
  1116. /**********************************************************************
  1117. *  generate_galaxy_stars()  - 
  1118. **********************************************************************/
  1119. static sint32 generate_galaxy_stars(void)
  1120.  
  1121. {  register P3       temp ;
  1122.    register sint32   i,j,k,col,obj,count ;
  1123.             sint32   tp ;
  1124.    register flot32   xc,yc,zc,s,t,factor,*f = (flot32 *)&tp ;
  1125.    register t_galaga *ga ;
  1126.    register t_stars  *st ;
  1127.  
  1128.    obj = glGenLists(1);
  1129.    glNewList(obj,GL_COMPILE) ;
  1130.    glBegin(GL_POINTS) ;
  1131.  
  1132.    for (count=k=0; k<STARSQ; k++)
  1133.      for (j=0; j<STARSQ; j++)  {
  1134.          ga = &ggaa[k][j] ;
  1135.  
  1136.          s = (flot32) (k+0.5)/STARSQ ;
  1137.          t = (flot32) (j+0.5)/STARSQ ;
  1138.          factor = 4.0*fexp(-40.0*((s-0.5)*(s-0.5) + (t-0.5)*(t-0.5))) - yc ; 
  1139.  
  1140.          xc = 0.5*GALAXY_EDGE - (j+0.5)*EDGESQ ;
  1141.          yc = 0.0 ;
  1142.          zc = 0.5*GALAXY_EDGE - (k+0.5)*EDGESQ ;
  1143.  
  1144.          tp = 0x3f800000 | (rand() << 8) ;
  1145.          tp = 2.0 * (*f - 1.0) * Counter.stars_per_square ;
  1146.  
  1147.          if (ga->count-12 > tp)  {
  1148.            st = &ga->stars[ga->count>>1];
  1149.            count++ ;
  1150.  
  1151.            glColor4f(st->r,st->g,st->b,0.25*st->a);
  1152.  
  1153.            temp.x = xc - st->x ;
  1154.            temp.y = yc - st->y*factor ; 
  1155.            temp.z = zc - st->z ;
  1156.            glVertex3fv(&temp.x) ;
  1157.            }
  1158.          }
  1159.  
  1160.    glEnd() ;
  1161.    glEndList();
  1162.  
  1163.    return(obj) ;
  1164. }
  1165.  
  1166. /********************************************************************** 
  1167. *  star_square_clip_check()  -  
  1168. **********************************************************************/
  1169. void star_square_clip_check(sint32 mm[4],sint32 flag[18][18],P3 *eye)
  1170.  
  1171. {  register flot32 tt,sto,dx,dz,save[3] ;
  1172.    register sint32 i,k,mask,q,*f ;
  1173.    register V4     *c ;
  1174.  
  1175.    for (f=flag[0],i=0; i<36; f+=9,i++)  {
  1176.      *(f+0) = 0 ; *(f+1) = 0 ; *(f+2) = 0 ;
  1177.      *(f+3) = 0 ; *(f+4) = 0 ; *(f+5) = 0 ;
  1178.      *(f+6) = 0 ; *(f+7) = 0 ; *(f+8) = 0 ; 
  1179.      }
  1180.  
  1181.    save[2] =  EDGESQ ;
  1182.    save[0] = -0.5*GALAXY_EDGE + mm[2]*save[2] ;
  1183.    save[1] = -0.5*GALAXY_EDGE + mm[0]*save[2] ;
  1184.  
  1185.    for (c=Counter.clop,mask=1,k=NUM_CLIP_PLANES; k>0; mask<<=1,c++,k--)  {
  1186.      sto = (flot32)4.0*save[2]*((c->y>0.0) ? -c->y : c->y) + c->x*eye->x + c->y*eye->y + c->z*eye->z ;
  1187.  
  1188.      dx  = c->x*save[2] ; 
  1189.      dz  = c->z*save[2] - (flot32)17.0*dx ;
  1190.      tt  = c->x*save[0] + c->z*save[1] ;
  1191.  
  1192.      for (f=flag[0],i=0; i<18; f+=18,i++)  {
  1193.        q = *(f+ 0) ; q |= mask ; if (tt < sto) *(f+ 0) = q ; tt+=dx ;
  1194.        q = *(f+ 1) ; q |= mask ; if (tt < sto) *(f+ 1) = q ; tt+=dx ;
  1195.        q = *(f+ 2) ; q |= mask ; if (tt < sto) *(f+ 2) = q ; tt+=dx ;
  1196.        q = *(f+ 3) ; q |= mask ; if (tt < sto) *(f+ 3) = q ; tt+=dx ;
  1197.        q = *(f+ 4) ; q |= mask ; if (tt < sto) *(f+ 4) = q ; tt+=dx ;
  1198.        q = *(f+ 5) ; q |= mask ; if (tt < sto) *(f+ 5) = q ; tt+=dx ;
  1199.        q = *(f+ 6) ; q |= mask ; if (tt < sto) *(f+ 6) = q ; tt+=dx ;
  1200.        q = *(f+ 7) ; q |= mask ; if (tt < sto) *(f+ 7) = q ; tt+=dx ;
  1201.        q = *(f+ 8) ; q |= mask ; if (tt < sto) *(f+ 8) = q ; tt+=dx ;
  1202.        q = *(f+ 9) ; q |= mask ; if (tt < sto) *(f+ 9) = q ; tt+=dx ;
  1203.        q = *(f+10) ; q |= mask ; if (tt < sto) *(f+10) = q ; tt+=dx ;
  1204.        q = *(f+11) ; q |= mask ; if (tt < sto) *(f+11) = q ; tt+=dx ;
  1205.        q = *(f+12) ; q |= mask ; if (tt < sto) *(f+12) = q ; tt+=dx ;
  1206.        q = *(f+13) ; q |= mask ; if (tt < sto) *(f+13) = q ; tt+=dx ;
  1207.        q = *(f+14) ; q |= mask ; if (tt < sto) *(f+14) = q ; tt+=dx ;
  1208.        q = *(f+15) ; q |= mask ; if (tt < sto) *(f+15) = q ; tt+=dx ;
  1209.        q = *(f+16) ; q |= mask ; if (tt < sto) *(f+16) = q ; tt+=dx ;
  1210.        q = *(f+17) ; q |= mask ; if (tt < sto) *(f+17) = q ; tt+=dz ;
  1211.        }
  1212.      }
  1213. }
  1214.  
  1215. /********************************************************************** 
  1216. *  sound_control()  -
  1217. **********************************************************************/
  1218. void sound_control(sint32 status,sint32 flag)
  1219.  
  1220. {  char a[16],b[16],c[16],str[128] ;
  1221.  
  1222.    if (status == 0)
  1223.      system("killall spay &") ;
  1224.    else  {
  1225.      strcpy(str,"nice spay ") ;
  1226.  
  1227.      switch (flag)  {
  1228.        case SND_BACK : strcat(str,"0 1 ") ; break ;
  1229.        case SND_BUTT : strcat(str,"1 0 ") ; break ;
  1230.        case SND_AUON : strcat(str,"2 0 ") ; break ;
  1231.        case SND_AUOF : strcat(str,"3 0 ") ; break ;
  1232.        default       : exit(0) ; break ;
  1233.        }
  1234.  
  1235.      sprintf(c,"%d",Counter.shmid) ;
  1236.      strcat(str,c) ;
  1237.      strcat(str,"&") ;
  1238.      system(str) ;
  1239.      }
  1240. }
  1241.  
  1242. /********************************************************************** 
  1243. *  stats_menu_stuff()  -
  1244. **********************************************************************/
  1245. static void stats_menu_stuff(t_boss *flaggs)
  1246.  
  1247. {  sint32   i,j,v,max;
  1248.    t_menu   plenu[24] ;
  1249.    char     ch[128];
  1250.    t_body   *tb,*tc,*suc ;
  1251.    t_stars  *st ;
  1252.  
  1253.    if (flaggs->suncount == 2)  {
  1254.      j = ((flaggs->suun_current == 0) ? 0xffff80ff : 0xff80ff80);
  1255.      }
  1256.    else j = 0xffffffff;
  1257.  
  1258.    suc = &flaggs->star[flaggs->suun_current];
  1259.  
  1260.    i = 0 ;
  1261.    make_new_item(&plenu[i],i,j,suc->ptr->name) ;
  1262.  
  1263.    for (i++; i<suc->ptr->moon_count+1; i++)  {
  1264.      tb = (t_body *)suc->next[i-1] ;
  1265.      j = (tb->ptr->tess >> 4) & 0xf ;
  1266.      v = ((j > 2 && j < 7) ? 0xff00ffff : 0xffffffff) ;
  1267.      make_new_item(&plenu[i],i,v,tb->ptr->name) ;
  1268.      }
  1269.  
  1270.    max = i ;
  1271.    draw2_menu(i,plenu) ;
  1272.    v = check2_menu(suc->ptr->moon_count+1,plenu) ;
  1273.  
  1274.    if (v == 0)  {
  1275.      st = &ggaa[Counter.z][Counter.x].stars[Counter.star_current] ;
  1276.  
  1277.      i = 5 ;
  1278.      sprintf(ch,"Name:     %s"        ,suc->ptr->name) ;
  1279.      make_new_item(&plenu[0],0,0xffffffff,ch) ;
  1280.      if (flaggs->suun_current == 0)
  1281.        sprintf(ch,"Abs Mag:  %.2f"      ,st->abs_mag) ;
  1282.      else sprintf(ch,"Abs Mag:  %.2f"      ,st->abs_mag2) ;
  1283.      make_new_item(&plenu[1],1,0xffffffff,ch) ;
  1284.      sprintf(ch,"Radius:   %.1f km"   ,suc->ptr->rad) ;
  1285.      make_new_item(&plenu[2],2,0xffffffff,ch) ;
  1286.      sprintf(ch,"Mass:     %.2e kg"   ,suc->ptr->mas) ;
  1287.      make_new_item(&plenu[3],3,0xffffffff,ch) ;
  1288.      sprintf(ch,"Temp:     %.0f deg." ,suc->ptr->apo) ;
  1289.      make_new_item(&plenu[4],4,0xffffffff,ch) ;
  1290.      }
  1291.    else  {
  1292.      tb = (t_body *)suc->next[v-1] ;
  1293.  
  1294.      i = 11 ;
  1295.      sprintf(ch,"Name:     %s"       ,tb->ptr->name) ;
  1296.      make_new_item(&plenu[0],0,0xffffffff,ch) ;
  1297.      sprintf(ch,"Radius:   %.0f km"  ,tb->ptr->rad) ; 
  1298.      make_new_item(&plenu[1],1,0xffffffff,ch) ;
  1299.      sprintf(ch,"Mass:     %.2e kg"  ,tb->ptr->mas) ; 
  1300.      make_new_item(&plenu[2],2,0xffffffff,ch) ;
  1301.      sprintf(ch,"Day:      %.2f days",tb->ptr->day) ; 
  1302.      make_new_item(&plenu[3],3,0xffffffff,ch) ;
  1303.      sprintf(ch,"AxialTilt:%.2f deg.",tb->ptr->apo) ; 
  1304.      make_new_item(&plenu[4],4,0xffffffff,ch) ;
  1305.      sprintf(ch,"Year:     %.2f days",tb->ptr->yer) ; 
  1306.      make_new_item(&plenu[5],5,0xffffffff,ch) ;
  1307.      sprintf(ch,"Orbit:    %.2e km"  ,tb->ptr->orb) ; 
  1308.      make_new_item(&plenu[6],6,0xffffffff,ch) ;
  1309.      sprintf(ch,"Eccent.:  %.3f"     ,tb->ptr->ecc) ; 
  1310.      make_new_item(&plenu[7],7,0xffffffff,ch) ;
  1311.      sprintf(ch,"Inclin.:  %.1f deg.",tb->ptr->inc) ; 
  1312.      make_new_item(&plenu[8],8,0xffffffff,ch) ;
  1313.      sprintf(ch,"Gravity:  %1.2f"    ,GRAV*tb->ptr->mas/(EARTHG*tb->ptr->rad*tb->ptr->rad)) ;
  1314.      make_new_item(&plenu[9],9,0xffffffff,ch) ;
  1315.      sprintf(ch,"Moons:    %d"       ,tb->ptr->moon_count) ; 
  1316.      make_new_item(&plenu[10],10,0xffffffff,ch) ;
  1317.  
  1318.      if (tb->ptr->r1 != 0.0)  {
  1319.        sprintf(ch,"Inner Ring: %.0f km" ,tb->ptr->r1) ; 
  1320.        make_new_item(&plenu[i],i,0xffffffff,ch) ;
  1321.        sprintf(ch,"Outer Ring: %.0f km" ,tb->ptr->r2) ; 
  1322.        make_new_item(&plenu[i+1],i+1,0xffffffff,ch) ;
  1323.        i += 2 ;
  1324.        }
  1325.      }
  1326.  
  1327.    if (max < i) max = i ;
  1328.  
  1329.    for (; i<max; i++) 
  1330.      make_new_item(&plenu[i],i,0x00002000,"") ;
  1331.  
  1332.    draw2_menu(i,plenu) ;
  1333.    sginap(30) ;
  1334.    i = check2_menu(i,plenu) ;
  1335.  
  1336.    if ((Counter.flags & USERM_FLAG) && (i < 10)) {
  1337.      switch (i)  {
  1338.        case 1:  tb->ptr->rad = spReadFloat(); break;
  1339.        case 2:  tb->ptr->mas = spReadFloat(); break;
  1340.        case 3:  tb->ptr->day = spReadFloat(); break;
  1341.        case 4:  tb->ptr->apo = spReadFloat(); break;
  1342.        case 5:  tb->ptr->yer = spReadFloat(); break;
  1343.        case 6:  tb->ptr->orb = spReadFloat(); object_planet_orbit(tb,0.0) ; break;
  1344.        case 7:  tb->ptr->ecc = spReadFloat(); object_planet_orbit(tb,0.0) ; break;
  1345.        case 8:  tb->ptr->inc = spReadFloat(); object_planet_orbit(tb,0.0) ; break;
  1346.        default: break;
  1347.        }
  1348.  
  1349.      return;
  1350.      }
  1351.  
  1352.    if (i == 10 && v > 0 && tb->ptr->moon_count > 0)  {
  1353.      for (i=0; i<tb->ptr->moon_count; i++) {
  1354.        tc = (t_body *) tb->next[i] ;
  1355.        sprintf(ch,"Name:     %s"       ,tc->ptr->name) ; 
  1356.        make_new_item(&plenu[i],i,0xffffffff,ch) ;
  1357.        }
  1358.  
  1359.      if (max < i) max = i ;
  1360.  
  1361.      for (; i<max; i++) 
  1362.        make_new_item(&plenu[i],i,0x00002000,"") ;
  1363.       
  1364.      draw2_menu(i,plenu) ;
  1365.      sginap(30) ;
  1366.      i = check2_menu(i,plenu) ;
  1367.  
  1368.      tc = (t_body *)tb->next[i] ;
  1369.  
  1370.      i = 10 ;
  1371.      sprintf(ch,"Name:     %s"       ,tc->ptr->name) ;
  1372.      make_new_item(&plenu[0],0,0xffffffff,ch) ;
  1373.      sprintf(ch,"Radius:   %.0f km"  ,tc->ptr->rad) ; 
  1374.      make_new_item(&plenu[1],1,0xffffffff,ch) ;
  1375.      sprintf(ch,"Mass:     %.2e kg"  ,tc->ptr->mas) ; 
  1376.      make_new_item(&plenu[2],2,0xffffffff,ch) ;
  1377.      sprintf(ch,"Day:      %.2f days",tc->ptr->day) ; 
  1378.      make_new_item(&plenu[3],3,0xffffffff,ch) ;
  1379.      sprintf(ch,"AxialTilt:%.2f deg.",tc->ptr->apo) ; 
  1380.      make_new_item(&plenu[4],4,0xffffffff,ch) ;
  1381.      sprintf(ch,"Year:     %.2f days",tc->ptr->yer) ; 
  1382.      make_new_item(&plenu[5],5,0xffffffff,ch) ;
  1383.      sprintf(ch,"Orbit:    %.2e km"  ,tc->ptr->orb) ; 
  1384.      make_new_item(&plenu[6],6,0xffffffff,ch) ;
  1385.      sprintf(ch,"Eccent.:  %.3f"     ,tc->ptr->ecc) ; 
  1386.      make_new_item(&plenu[7],7,0xffffffff,ch) ;
  1387.      sprintf(ch,"Inclin.:  %.1f deg.",tc->ptr->inc) ; 
  1388.      make_new_item(&plenu[8],8,0xffffffff,ch) ;
  1389.      sprintf(ch,"Gravity:  %1.2f"    ,GRAV*tc->ptr->mas/(EARTHG*tc->ptr->rad*tc->ptr->rad)) ;
  1390.      make_new_item(&plenu[9],9,0xffffffff,ch) ;
  1391.  
  1392.      if (max < i) max = i ;
  1393.  
  1394.      for (; i<max; i++) 
  1395.        make_new_item(&plenu[i],i,0x00002000,"") ;
  1396.  
  1397.      draw2_menu(i,plenu) ;
  1398.      sginap(30) ;
  1399.  
  1400.      i = check2_menu(i,plenu) ;
  1401.  
  1402.      if ((Counter.flags & USERM_FLAG) && (i < 10)) {
  1403.        switch (i)  {
  1404.          case 1:  tc->ptr->rad = spReadFloat(); break;
  1405.          case 2:  tc->ptr->mas = spReadFloat(); break;
  1406.          case 3:  tc->ptr->day = spReadFloat(); break;
  1407.          case 4:  tc->ptr->apo = spReadFloat(); break;
  1408.          case 5:  tc->ptr->yer = spReadFloat(); break;
  1409.          case 6:  tc->ptr->orb = spReadFloat(); object_planet_orbit(tc,0.0) ; break;
  1410.          case 7:  tc->ptr->ecc = spReadFloat(); object_planet_orbit(tc,0.0) ; break;
  1411.          case 8:  tc->ptr->inc = spReadFloat(); object_planet_orbit(tc,0.0) ; break;
  1412.          default: break;
  1413.          }
  1414.  
  1415.        return;
  1416.        }
  1417.      }
  1418. }
  1419.  
  1420. /********************************************************************** 
  1421. *  autopilot_menu_stuff()  -
  1422. **********************************************************************/
  1423. static sint32 autopilot_menu_stuff(t_boss *flaggs)
  1424.  
  1425. {  sint32   i,j,v,aupi[3];
  1426.    t_body   *tb;
  1427.    flot32   d,timespan ;
  1428.    V3       u ;
  1429.    t_menu   plenu[24] ;
  1430.    t_galaga *ga ;
  1431.    P3       pp ;
  1432.  
  1433.    i = 0 ;
  1434.    if (Counter.status == STELL_STAT)  {
  1435.      for (; i<flaggs->star[flaggs->suun_current].ptr->moon_count; i++)  {
  1436.        tb = (t_body *)flaggs->star[flaggs->suun_current].next[i] ;
  1437.        j = (tb->ptr->tess >> 4) & 0xf ;
  1438.        v = ((j > 2 && j < 7) ? 0xff00ffff : 0xffffffff) ;
  1439.        make_new_item(&plenu[i],i,v,tb->ptr->name) ;
  1440.        }
  1441.  
  1442.      make_new_item(&plenu[i],i,0xffffffff,"New Star System") ;
  1443.  
  1444.      draw2_menu(i+1,plenu) ;
  1445.      aupi[0] = check2_menu(flaggs->star[flaggs->suun_current].ptr->moon_count+1,plenu) ;
  1446.      }
  1447.  
  1448.    if ((Counter.status == STELL_STAT && aupi[0] == flaggs->star[flaggs->suun_current].ptr->moon_count) || Counter.status != STELL_STAT)  {
  1449.      for (j=0; j<i; j++)
  1450.        strcpy(plenu[j].mes0,"") ;
  1451.  
  1452.      make_new_item(&plenu[i],i,0xffffffff,"Enter Star Number <CR>") ;
  1453.      draw2_menu(i+1,plenu) ;
  1454.  
  1455.      if (!spReadStar(aupi))
  1456.        return(0);
  1457.  
  1458.      ga = &ggaa[aupi[2]][aupi[1]] ;
  1459.  
  1460.      if (aupi[0] >= ga->count) 
  1461.        return(0);
  1462.  
  1463.      Counter.spline.p2.x = ga->stars[aupi[0]].x - 0.5*GALAXY_EDGE + (aupi[1]+0.5)*EDGESQ ;
  1464.      Counter.spline.p2.y = ga->stars[aupi[0]].y ;
  1465.      Counter.spline.p2.z = ga->stars[aupi[0]].z - 0.5*GALAXY_EDGE + (aupi[2]+0.5)*EDGESQ ;
  1466.  
  1467.      if (Counter.status == STELL_STAT)  {
  1468.        pp.x = ga->stars[Counter.star_current].x - 0.5*GALAXY_EDGE + (Counter.x+0.5)*EDGESQ ;
  1469.        pp.y = ga->stars[Counter.star_current].y ;
  1470.        pp.z = ga->stars[Counter.star_current].z - 0.5*GALAXY_EDGE + (Counter.z+0.5)*EDGESQ ;
  1471.  
  1472.        pp.x = Counter.spline.p2.x - pp.x ;
  1473.        pp.y = Counter.spline.p2.y - pp.y ;
  1474.        pp.z = Counter.spline.p2.z - pp.z ;
  1475.        d = fsqrt(pp.x*pp.x + pp.y*pp.y + pp.z*pp.z) ;
  1476.  
  1477.        Counter.spline.p2.x = 1.0*PRTOKM*pp.x/d ;
  1478.        Counter.spline.p2.y = 1.0*PRTOKM*pp.y/d ;
  1479.        Counter.spline.p2.z = 1.0*PRTOKM*pp.z/d ;
  1480.  
  1481.        Counter.spline.v1.x = Counter.spline.v2.x = 100000.0 * Counter.vnorm.x ;
  1482.        Counter.spline.v1.y = Counter.spline.v2.y = 100000.0 * Counter.vnorm.y ;
  1483.        Counter.spline.v1.z = Counter.spline.v2.z = 100000.0 * Counter.vnorm.z ;
  1484.        }
  1485.      else  {
  1486.        Counter.spline.v1.x = Counter.spline.v2.x = 2.0 * Counter.vnorm.x ; 
  1487.        Counter.spline.v1.y = Counter.spline.v2.y = 2.0 * Counter.vnorm.y ; 
  1488.        Counter.spline.v1.z = Counter.spline.v2.z = 2.0 * Counter.vnorm.z ; 
  1489.        }
  1490.  
  1491.      timespan = 60.0 ;
  1492.      Counter.spline.newstar[0] = aupi[0] ;
  1493.      Counter.spline.newstar[1] = aupi[1] ;
  1494.      Counter.spline.newstar[2] = aupi[2] ;
  1495.      Counter.flags |= AUTOP_FLAG ;
  1496.      }
  1497.  
  1498.    else   {
  1499.      if (aupi[0] < 0 || aupi[0] >= flaggs->star[flaggs->suun_current].ptr->moon_count)
  1500.        return(0);
  1501.  
  1502.      tb = (t_body *)flaggs->star[flaggs->suun_current].next[aupi[0]] ;
  1503.  
  1504.      u.x = tb->posit.x - flaggs->star[flaggs->suun_current].posit.x ;
  1505.      u.y = tb->posit.y - flaggs->star[flaggs->suun_current].posit.y ;
  1506.      u.z = tb->posit.z - flaggs->star[flaggs->suun_current].posit.z ;
  1507.      d = fsqrt(u.x*u.x + u.y*u.y + u.z*u.z) ;
  1508.      u.x /= d ; u.y /= d ; u.z /= d ;
  1509.  
  1510.      Counter.spline.p2.x = Counter.eye.x + tb->posit.x - 6.0*tb->ptr->rad*u.x ;
  1511.      Counter.spline.p2.y = Counter.eye.y + tb->posit.y - 6.0*tb->ptr->rad*u.y ;
  1512.      Counter.spline.p2.z = Counter.eye.z + tb->posit.z - 6.0*tb->ptr->rad*u.z ;
  1513.  
  1514.      Counter.spline.v2.x = 1.0e7*u.x ;
  1515.      Counter.spline.v2.y = 1.0e7*u.y ;
  1516.      Counter.spline.v2.z = 1.0e7*u.z ;
  1517.  
  1518.      Counter.spline.v1.x = 100000.0 * Counter.vnorm.x ; 
  1519.      Counter.spline.v1.y = 100000.0 * Counter.vnorm.y ; 
  1520.      Counter.spline.v1.z = 100000.0 * Counter.vnorm.z ; 
  1521.  
  1522.      timespan = 20.0 ;
  1523.      Counter.spline.newstar[0] = -2 ;
  1524.      Counter.spline.newstar[1] = -2 ;
  1525.      Counter.spline.newstar[2] = -2 ;
  1526.      Counter.flags |= AUTOP_FLAG ;
  1527.      }
  1528.  
  1529.    Counter.spline.p1 = Counter.eye ;
  1530.    Counter.spline.t1 = Counter.D ;
  1531.    Counter.spline.t2 = Counter.D + timespan/(24.0*3600.0) + delta_timer() ;
  1532.  
  1533.    return(1);
  1534. }
  1535.  
  1536. #if STATS
  1537. /********************************************************************** 
  1538. *  statistics()  -
  1539. **********************************************************************/
  1540. static sint32 statistics(long flag)
  1541.  
  1542. {  sint32 i,ptr[16];
  1543.  
  1544.    if (flag) {
  1545.      for (i=0; i<256; i++)
  1546.        feed_buff[i] = 0;
  1547.  
  1548.      ptr[0] = (long)feed_buff;
  1549.      ptr[1] = 1024;
  1550.      glcompat(1009,(long)ptr);
  1551.      }
  1552.    else  {
  1553.      glcompat(1012,0);
  1554.  
  1555.      ptr[0] = (long)feed_buff;
  1556.      ptr[1] = 1024;
  1557.      glcompat(1010,(long)ptr);
  1558.      
  1559.      printf("0x%08x 0x%08x\n",feed_buff[0],feed_buff[1]);
  1560.      for (i=2; i<18; i+=4)
  1561.        printf("0x%08x 0x%08x 0x%08x 0x%08x\n",feed_buff[i],feed_buff[1+i],feed_buff[2+i],feed_buff[3+i]);
  1562.      }
  1563. }
  1564. #endif
  1565.  
  1566.